<?php
require_once '../Classes/Feed.php';
require_once '../Classes/Entry.php';
require_once '../Classes/FeedsList.php';

class OpmlSimple
{
	private function parse_rec(SimpleXMLElement $xml, array& $feedlist)
	{
		foreach ($xml as $outline)
		{
			if (!isset($outline['xmlUrl']))
			{
				//Folder/tag, recursive call
				$this->parse_rec($outline->outline, $feedlist);
			}
			else
			{
				$feed = new Feed();
				$feed->title = (string)$outline['title'];
				$feed->link = (string)$outline['xmlUrl'];
				array_push($feedlist, $feed);
			}
		}
	}

	public function parse($path)
	{
		$xml= simplexml_load_file($path);
		$arrFeeds = new FeedsList();
		$arrFeeds->feedsList = array();
		$this->parse_rec($xml->body->outline, $arrFeeds->feedsList);
		return $arrFeeds;
	}
}

$opml = new OpmlSimple;
$list = $opml->parse("./google-reader-subscriptions.xml");
echo (string)$list;
?>